/*
 * @Author: Jiraiya
 * @Date: 2020-05-22 14:41:40
 * @LastEditors: Jiraiya
 * @LastEditTime: 2020-05-22 14:42:41
 * @Description: 
 */ 

const POOL_SIZE = 10;
const traverseContextPool = [];

/**
 * @description: 通过变量池获取变量
 * @param {type} 
 * @return: 
 */
function getPooledTraverseContext(
    mapResult,
    keyPrefix,
    mapFunction,
    mapContext,
  ) {
    if (traverseContextPool.length) {
      const traverseContext = traverseContextPool.pop();
      traverseContext.result = mapResult;
      traverseContext.keyPrefix = keyPrefix;
      traverseContext.func = mapFunction;
      traverseContext.context = mapContext;
      traverseContext.count = 0;
      return traverseContext;
    } else {
      return {
        result: mapResult,
        keyPrefix: keyPrefix,
        func: mapFunction,
        context: mapContext,
        count: 0,
      };
    }
}

module.exports = {
    getPooledTraverseContext,
}